package cn.edu.nju.ws.sview.rdf;

/**
 * blank node
 * 
 * @author Gong Saisai
 * 
 */
public class BlankNode extends Resource {
	private RDFDocument rdfDocument = null;
	private int blankNodeID;
	private String label = null;

	/**
	 * 
	 * @param rdfDocument
	 *            该blank node所属的RDF文档
	 * @param blankNodeID
	 *            该blank node在其所属RDF文档包含的所有blank node中的编号
	 */
	BlankNode(RDFDocument rdfDocument, int blankNodeID) {
		this.rdfDocument = rdfDocument;
		this.blankNodeID = blankNodeID;
	}

	/**
	 * 
	 * @return 该blank node所属的RDF文档
	 */
	public RDFDocument getRDFDocument() {
		return this.rdfDocument;
	}
	
	public String getLabel(String lang){
		this.label = ResourceFactory.getInstance().getResouceLabel(this,lang) ;
		if(this.label==null){
			return new String("_:"+this.blankNodeID);
		}else
			return this.label;
	}

	/**
	 * 
	 * @return 该blank node在其所属RDF文档包含的所有blank node中的编号
	 */
	public int getBlankNodeID() {
		return this.blankNodeID;
	}

	public boolean equals(Object obj) {
		if (obj instanceof BlankNode) {
			BlankNode bnode = (BlankNode) obj;
			if (this.rdfDocument.equals(bnode.getRDFDocument()) && (this.blankNodeID == bnode.getBlankNodeID())) {
				return true;
			}
		}
		return false;
	}
	
	public int hashCode(){
		return this.rdfDocument.hashCode()*31+this.blankNodeID;
	}
	
	public String toString() {
		return "_:IN" + this.rdfDocument.toString() + "NO" + this.blankNodeID;
	}
}